﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;

namespace Assets.Script.Human.Enemy.Actions
{
    class BeAtk : EnemyActionBase, IAction
    {
        float time = 0;
        Vector3 offSetDir;
        float offSetDistance;
        float offSetTime;
        float offSetSpeed;
        public BeAtk(EnemyBody body) : base(body)
        {
        }

        public void Interrupt()
        {
            state.BeAttacked = false;
            //animator.SetTrigger("beAtkEnd");
        }

        public void OnEnter(ref object[] o)
        {
            state.BeAttacked = true;
            //animator.SetTrigger("beAtk");

            time = 0;

            offSetDistance = (float)o[0];
            offSetTime = (float)o[1];
            offSetDir = (Vector3)o[2];

            offSetSpeed = offSetDistance / offSetTime;
        }


        public void OnFixedUpdate()
        {
            
            if (time<offSetTime)
            {
                time += Time.fixedDeltaTime;
                body.transform.Translate(offSetDir * offSetSpeed * Time.fixedDeltaTime,Space.World);
            }
            else
            {
                Interrupt();
            }
        }

        public void OnUpdate()
        {

        }
    }
}
